package com.woniuxy.order.controller;


import com.woniuxy.order.entity.Ticket_order;
import com.woniuxy.order.service.UserService;
import com.woniuxy.ticketcommon.ResponceResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.client.RestTemplate;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author order
 * @since 2021-02-22
 */
@Api(tags = "订单管理接口")
@Slf4j
@RestController
@RequestMapping("/order")
public class Ticket_orderController {

    @Autowired
    private RestTemplate restTemplate;

    @ApiOperation("调用用户微服务的方法1")
    @GetMapping("add")
    public String add() {

        log.debug("order Add");

        String serviceUser = "http://ticket-user/user/add";
//
//        try {
//            URL url=new URL(serviceUser);
//            URLConnection urlConnection=url.openConnection();
//            InputStream inputStream=urlConnection.getInputStream();
//
//            BufferedReader reader=new BufferedReader(new InputStreamReader(inputStream));
//
//            log.debug(reader.readLine());
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        ResponseEntity<String> forEntity = restTemplate.getForObject(serviceUser, String.class);
        String forObject = restTemplate.getForObject(serviceUser, String.class);
        System.out.println(forObject);
        return "order Add";
    }

    @Autowired
    private UserService userService;

    @ApiOperation("添加用户的接口")
    //（{}）里面可能是数组
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名", defaultValue = "李四"),
            @ApiImplicitParam(name = "address", value = "用户地址", defaultValue = "深圳", required = true)
    }
    )
    @GetMapping("add2")
    public String add2(@RequestBody Ticket_order order) {

        Ticket_order Ticket_order = new Ticket_order();
        return userService.add();
    }

    @ApiOperation("下订单的接口")
    @PostMapping("orderDown")
    public ResponceResult<Object> orderDown() {


        return new ResponceResult<>(200, "下单成功");
    }


}

